package org.hadoop.seq;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.SequenceFile.Reader;
import org.apache.hadoop.io.Writable;
/**
 * 通过reader.getValueClass()<br>
 * getKeyClass()获取类型
 */
public class ReadSequenceFile2 {
    public static void main(String[] args)  throws Exception{
        Configuration config = new Configuration();
        Reader.Option op1 = Reader.file(new Path("file:///D:/a/1.seq"));
        SequenceFile.Reader reader = new SequenceFile.Reader(config,op1);
        //获取key和value类型
        Writable key =  (Writable) reader.getKeyClass().newInstance();
        Writable value = (Writable)reader.getValueClass().newInstance();
        //读取数据
        while(reader.next(key, value)) {
            System.out.println(key.toString()+"\t"+value.toString());
        }
        reader.close();
    }
}